package cn.virens.database.serviceimpl.sys;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import cn.virens.database.common.BaseServiceImpl;
import cn.virens.database.common.ExampleWrapper;
import cn.virens.database.mysql.mapper.sys.SysResourceMapper;
import cn.virens.database.mysql.model.sys.SysResource;
import cn.virens.database.service.sys.SysResourceService;
import cn.virens.exception.APIException;

/**
 * 资源管理 - sys_resource
 *
 * @author Virens
 * @since  2018-08-25 15:40:43
 */
@Service
public class SysResourceServiceImpl extends BaseServiceImpl<SysResourceMapper, SysResource> implements SysResourceService {

	public SysResourceServiceImpl() {
		super(SysResource.class);
	}

	@Override
	public List<SysResource> selectAll(Map<String, Object> param) {
		ExampleWrapper example = ExampleWrapper.of(clazz);
		example.createCriteria(param);
		example.orderBy("pid").asc();
		example.orderBy("id").asc();

		return mBaseMapper.selectByExample(example);
	}

	@Override
	public SysResource update(SysResource record) {
		record.setCreateTime(null);
		record.setIdentity(null);
		record.setLinkurl(null);

		return super.update(record);
	}

	@Override
	public SysResource insert(SysResource record) {
		throw new APIException("DISABLE_API", "Disable create the resource!");
	}

	@Override
	public int delete(Serializable id) {
		throw new APIException("DISABLE_API", "Disable delete the resource!");
	}
}
